/*
 * @lc app=leetcode.cn id=693 lang=cpp
 *
 * [693] 交替位二进制数
 */

// @lc code=start
class Solution {
public:
    bool hasAlternatingBits(int n) {
        int flag = n & 1;
        n = n/2;
        while(n) {
            int tmp = n & 1;
            if(tmp == flag) {
                return false;
            }
            flag = tmp;
            n /= 2; 
        }
        return true;
    }
};
// @lc code=end

